/*    */ package tools;
/*    */ 
/*    */ import javax.crypto.Cipher;
/*    */ import javax.crypto.spec.IvParameterSpec;
/*    */ import javax.crypto.spec.SecretKeySpec;
/*    */ import javax.xml.bind.DatatypeConverter;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class AES
/*    */ {
/* 14 */   private Cipher oCipher = null;
/* 15 */   private SecretKeySpec specKey = null;
/* 16 */   private IvParameterSpec specIV = null;
/*    */ 
/*    */   
/*    */   public AES(String key, String iv) throws Exception {
/* 20 */     this.oCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
/*    */     
/* 22 */     byte[] byKeys = key.getBytes("UTF-8");
/* 23 */     byte[] byIVs = iv.getBytes("UTF-8");
/*    */     
/* 25 */     this.specKey = new SecretKeySpec(byKeys, "AES");
/* 26 */     this.specIV = new IvParameterSpec(byIVs);
/*    */   }
/*    */ 
/*    */   
/*    */   public String Encrypt(String originalValue) throws Exception {
/* 31 */     int nLength = 0;
/* 32 */     String szResult = null;
/*    */     
/* 34 */     this.oCipher.init(1, this.specKey, this.specIV);
/*    */     
/* 36 */     byte[] bySource = originalValue.getBytes("UTF-8");
/*    */     
/* 38 */     byte[] byCiphers = new byte[this.oCipher.getOutputSize(bySource.length)];
/*    */     
/* 40 */     nLength = this.oCipher.update(bySource, 0, bySource.length, byCiphers, 0);
/* 41 */     nLength += this.oCipher.doFinal(byCiphers, nLength);
/*    */     
/* 43 */     szResult = DatatypeConverter.printBase64Binary(byCiphers);
/*    */     
/* 45 */     return szResult;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public String Decrypt(String encryptValue) throws Exception {
/* 51 */     String szResult = null;
/*    */     
/* 53 */     byte[] byCiphers = DatatypeConverter.parseBase64Binary(encryptValue);
/*    */     
/* 55 */     this.oCipher.init(2, this.specKey, this.specIV);
/*    */     
/* 57 */     byte[] bySource = new byte[this.oCipher.getOutputSize(byCiphers.length)];
/*    */     
/* 59 */     int nLength = this.oCipher.update(byCiphers, 0, byCiphers.length, bySource, 0);
/* 60 */     nLength += this.oCipher.doFinal(bySource, nLength);
/*    */     
/* 62 */     szResult = new String(bySource, 0, nLength, "UTF-8");
/*    */     
/* 64 */     return szResult;
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\tools\AES.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */